<#assign module="freight"/>
<@override name="header">
</@override>
<@override name="body">
<link rel="stylesheet" href="${ctx}/assets/css/chosen.min.css">
<style>
.chosen-container{font-size: 14px;min-width: 370px;}
</style>
<style>
.panel-default {
    /* border-color: #ddd; */
}

.car_img_div {
	width:auto;height:34vh;margin:0px auto;padding:0px;overflow-y: overlay;
}

.car_img_div .car_img_bor {
	text-align:center;margin:10px 0px 0px 0px;border:2px dashed #fff;border-radius:10px;cursor:pointer;padding:5px 0px;display: inline-block;
}

.car_img_div .car_img_bor div{
	width:110px;text-align:center;margin-top:5px;font-size:12px;text-overflow:ellipsis;
}

</style>
<div class="tabbable tabs-left">
	<div class="row">
		<div class="col-xs-12">
			<div class="orders-navt">
				<ul class="orders-nav">
					<@shiro.hasPermission name='freightTruck'>
	                	<li class="orders-notclick"><a  href="${ctx}/freight/trucks">车辆</a></li>
	                </@shiro.hasPermission>
	                 <@shiro.hasPermission name='freightTruck'>
	                	<li class="orders-click"><a  href="${ctx}/freight/truckTypes">类型</a></li>
	                </@shiro.hasPermission>
	            </ul>
	    	</div>
	    	<div class="orders-navh">
		       <button class="pull-right btn btn-primary addCar"><i class="icon-plus"></i>&nbsp;添加货车类型</button>
			</div>
		</div>
	</div>
</div>


<!--列表-->
<div class="tabta-content">  	
	<table class="table  table-striped table-hover table-striped">
		<tbody id="carType_tbody">
			<tr>
					<th class="col-xs-3" >货车类型(<span style="font-size:14px;color:red;">点击车型名称展开或收起</span>)</th>
					<th class="col-xs-3" >有无入城证</th>
			        <th class="col-xs-3">APP上显示顺序(从左到右 由小到大)</th>
			        <th class="col-xs-3" style='text-align:right;padding-right:140px;'>操作</th>
			</tr>
		</tbody>
	</table>
	<div id="carTypeList">
	
    </div>
	<div>
		<ul class="pagination pull-left pagination-sm pageshow" id="carTypetotal">
		</ul>
	</div>
	<ul class="pagination pull-left pagination-sm pageshow" style="display:none;">
		<li><a></a></li>
	</ul>
	<ul class="pagination pull-left pagination-sm pagedata" style="display:none;">
    </ul>
</div>
<!--添加货车类型-->
<div class="form-horizontal">
	<div class="modal fade" id="dialog_car" data-backdrop="static">
	   <div class="modal-dialog" style="width:60%;margin:50px auto 0px auto;">
	     <div class="modal-content">
		     <form action=""  method="post">
		    	<div class="modal-header">
			        <button type="button" class="close" data-dismiss="modal" aria-hidden="false">&times;</button>
		        	<h4 class="modal-title">添加货车类型</h4>
		        </div>
		        <div class="modal-header">
			        <div class="form-group" style="margin-bottom:0px">
		                <label class="col-sm-2 control-label">货车类型:</label>
		                <div class="col-sm-3">
			                <input id="typeName"  class="form-control" placeholder="如:面包车、金杯车、微货车、厢货车"></input>
		                </div>
		                <label class="col-sm-2 control-label">排列顺序:</label>
		                <div class="col-sm-3">
		                	<input id="sequence" type="number" class="form-control"></input>
		                </div>
					 </div>
		        </div>
		        
		        <div class="modal-header" style="border-bottom:none">
			        <div class="form-group"  style="margin-bottom:0px">
		                <label class="col-sm-2 control-label">货箱长:</label>
		                <div class="col-sm-3">
			                <div class="input-group">
							  <input id="len" type="number" min="1" max="30" class="form-control" >
							  <span class="input-group-addon">米</span>
							 </div>
		                </div>
		                <label class="col-sm-2 control-label">货箱宽:</label>
		                <div class="col-sm-3">
			                <div class="input-group">
							  <input id="width" type="number" min="1" max="30" class="form-control" >
							  <span class="input-group-addon">米</span>
							 </div>
		                </div>
					 </div>
		        </div>
		        
		        <div class="modal-header" style="border:none;padding-top:0px;padding-bottom:0px">
			        <div class="form-group"  style="margin-bottom:0px;">
		                <label class="col-sm-2 control-label">货箱高:</label>
		                <div class="col-sm-3">
			                <div class="input-group">
							  <input id="height" type="number" min="1"  max="30" class="form-control" >
							  <span class="input-group-addon">米</span>
							 </div>
		                </div>
		                <label class="col-sm-2 control-label">载重量:</label>
		                <div class="col-sm-3">
			                <div class="input-group">
							  <input id="carryingCapacity" type="number" min="0" max="100" class="form-control" >
							  <span class="input-group-addon">吨</span>
							 </div>
		                </div>
					 </div>
		        </div>
		        
		        <div class="modal-header">
			        <div class="form-group" style="margin-bottom:0px">
		               <label class="col-sm-2 control-label">入城证:</label>
		                <div class="col-sm-3">
		                  <div class="input-group" style="margin-top:6px;">
		                	<input id="wu1" type="radio"  name="cangointotown" checked value="false"/><label for="wu1">无</label>&nbsp&nbsp&nbsp
							<input id="you2" type="radio" name="cangointotown"  value="true"/><label for="you1">有</label>
		                  </div>
		                </div>
					 </div>
		        </div>
	        
			    <div class="modal-body">
			       <div class="modal-body" style="height:35vh;padding:2px;">
			       		<p hidden="hidden"><input id="car_img" name="img" /></p>
			       		<div class="car_img_div" id="car_img_create">
			       			
			       			<div class="car_img_bor">
			       				<img src="${ctx}/assets/img/freight_xiaomianbaoche2x.png" width="70px" height="70px" />
			       				<div>建议为小面包车</div>
			       			</div>
			       			
			       			<div class="car_img_bor">
			       				<img src="${ctx}/assets/img/freight_damianbaoche2x.png" width="70px" height="70px" />
			       				<div>建议为大面包车</div>
			       			</div>
			       			
			       			<div class="car_img_bor">
			       				<img src="${ctx}/assets/img/freight_xiaokache2x.png" width="70px" height="70px" />
			       				<div>建议为小卡车</div>
			       			</div>
			       			
			       			<div class="car_img_bor">
			       				<img src="${ctx}/assets/img/freight_dakache2x.png" width="70px" height="70px" />
			       				<div>建议为大卡车</div>
			       			</div>
			       			
			       			<div class="car_img_bor">
			       				<img src="${ctx}/assets/img/freight_pikache2x.png" width="70px" height="70px" />
			       				<div>建议为皮卡车</div>
			       			</div>
			       			
			       			<div class="car_img_bor">
			       				<img src="${ctx}/assets/img/freight_xiaohuoche2x.png" width="70px" height="70px" />
			       				<div>建议为小货车</div>
			       			</div>
			       			
			       			<div class="car_img_bor">
			       				<img src="${ctx}/assets/img/freight_zhonghuoche2x.png" width="70px" height="70px" />
			       				<div>建议为中货车</div>
			       			</div>
			       			
			       			<div class="car_img_bor">
			       				<img src="${ctx}/assets/img/freight_dahuoche2x.png" width="70px" height="70px" />
			       				<div>建议为大货车</div>
			       			</div>
			       			
			       			<div class="car_img_bor">
			       				<img src="${ctx}/assets/img/freight_banshihuoche2x.png" width="70px" height="70px" />
			       				<div>建议为板式货车</div>
			       			</div>
			       			
			       		</div>
			       
			       </div>
				   <div class="form-group">
                 	  <div class="col-sm-5"></div>
                	  <div class="col-sm-3">
					      <input  type="button" class="btn btn-primary" id="save" value="确定">
					      <button type="button" class="btn btn-default" id="close_modal">关闭</button>
		        	  </div>
		           </div>
		        </div>
		      </form>
	     	</div>
	     </div>
	  </div>
	</div>
</div>
<!--修改货车类型信息-->
<div class="form-horizontal">
	<div class="modal fade" id="dialog_car_update"  style=""data-backdrop="static">
	   <div class="modal-dialog"  style="width:60%;margin:50px auto 0px auto;">
	     <div class="modal-content">
	     	<form action=""  method="post">
		    	<div class="modal-header">
			        <button type="button" class="close" data-dismiss="modal" aria-hidden="false">&times;</button>
		        	<h4 class="modal-title">修改货车类型信息</h4>
		        </div>
			    <div class="modal-header">
				    <div class="form-group" style="margin-bottom:0px">
			            <label class="col-sm-2 control-label">货车类型:</label>
			            <div class="col-sm-3">
				            <input id="typeName2"  class="form-control" placeholder="如:面包车、金杯车、微货车、厢货车"></input>
			            </div>
		                <label class="col-sm-2 control-label">排列顺序:</label>
		                <div class="col-sm-3">
			               	<input id="sequence2" type="number" class="form-control"></input>
		               </div>
			        </div>
			    </div>
		        
		        <div class="modal-header" style="border-bottom:none">
			        <div class="form-group"  style="margin-bottom:0px">
		                <label class="col-sm-2 control-label">货箱长:</label>
		                <div class="col-sm-3">
			                <div class="input-group">
							  <input id="len2" type="number" min="1" max="20" class="form-control" >
							  <span class="input-group-addon">米</span>
							 </div>
		                </div>
		                <label class="col-sm-2 control-label">货箱宽:</label>
		                <div class="col-sm-3">
			                <div class="input-group">
							  <input id="width2" type="number" min="1" max="20" class="form-control" >
							  <span class="input-group-addon">米</span>
							 </div>
		                </div>
					 </div>
		        </div>
	        
		        <div class="modal-header" style="border:none;padding-top:0px;padding-bottom:0px">
			        <div class="form-group"  style="margin-bottom:0px;">
		                <label class="col-sm-2 control-label">货箱高:</label>
		                <div class="col-sm-3">
			                <div class="input-group">
							  <input id="height2" type="number" min="1"  max="20" class="form-control" >
							  <span class="input-group-addon">米</span>
							 </div>
		                </div>
		                <label class="col-sm-2 control-label">载重量:</label>
		                <div class="col-sm-3">
			                <div class="input-group">
							  <input id="carryingCapacity2" type="number" min="0" max="100" class="form-control" >
							  <span class="input-group-addon">吨</span>
							 </div>
		                </div>
					 </div>
		        </div>
	        
		        <div class="modal-header">
			        <div class="form-group" style="margin-bottom:0px">
		               <label class="col-sm-2 control-label">入城证:</label>
		                <div class="col-sm-3">
		                  <div class="input-group" style="margin-top:6px;">
		                	<input id="wu" type="radio"  name="cangointotown2" checked value="false"/><label for="wu">无</label>&nbsp&nbsp&nbsp
							<input id="you" type="radio" name="cangointotown2"  value="true"/><label for="you">有</label>
		                  </div>
		                </div>
					 </div>
		        </div>
        
			    <div class="modal-body">
			       <div class="modal-body" style="height:35vh;padding:2px">
			       		<p hidden="hidden"><input id="car_img2" name="img" /></p>
			       		<div class="car_img_div" id="car_img_update">
			       			
			       			<div class="car_img_bor">
			       				<img src="${ctx}/assets/img/freight_xiaomianbaoche2x.png" width="70px" height="70px" />
			       				<div>建议为小面包车</div>
			       			</div>
			       			
			       			<div class="car_img_bor">
			       				<img src="${ctx}/assets/img/freight_damianbaoche2x.png" width="70px" height="70px" />
			       				<div>建议为大面包车</div>
			       			</div>
			       			
			       			<div class="car_img_bor">
			       				<img src="${ctx}/assets/img/freight_xiaokache2x.png" width="70px" height="70px" />
			       				<div>建议为小卡车</div>
			       			</div>
			       			
			       			<div class="car_img_bor">
			       				<img src="${ctx}/assets/img/freight_dakache2x.png" width="70px" height="70px" />
			       				<div>建议为大卡车</div>
			       			</div>
			       			
			       			<div class="car_img_bor">
			       				<img src="${ctx}/assets/img/freight_pikache2x.png" width="70px" height="70px" />
			       				<div>建议为皮卡车</div>
			       			</div>
			       			
			       			<div class="car_img_bor">
			       				<img src="${ctx}/assets/img/freight_xiaohuoche2x.png" width="70px" height="70px" />
			       				<div>建议为小货车</div>
			       			</div>
			       			
			       			<div class="car_img_bor">
			       				<img src="${ctx}/assets/img/freight_zhonghuoche2x.png" width="70px" height="70px" />
			       				<div>建议为中货车</div>
			       			</div>
			       			
			       			<div class="car_img_bor">
			       				<img src="${ctx}/assets/img/freight_dahuoche2x.png" width="70px" height="70px" />
			       				<div>建议为大货车</div>
			       			</div>
			       			
			       			<div class="car_img_bor">
			       				<img src="${ctx}/assets/img/freight_banshihuoche2x.png" width="70px" height="70px" />
			       				<div>建议为板式货车</div>
			       			</div>
			       			
			       		</div>
			       
			       </div>
				   <div class="form-group">
	                 	<div class="col-sm-5">
	                	</div>
	                	<div class="col-sm-3">
						    <input  type="button" class="btn btn-primary" id="update" value="保存">
						    <button type="button" class="btn btn-default" id="close_modal_update">取消</button>
			        	</div>
			       </div>
		  		</form>
	     	</div>
	     </div>
	  </div>
	</div>
</div>
<!--开通公司-->
<div class="form-horizontal">
	<div class="modal fade" id="dialog_truckTypeCompany_create">
	   <div class="modal-dialog">
	     <div class="modal-content">
	    	<div class="modal-header">
		        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
	        	<h4 class="modal-title">开通类型</h4>
	        </div>
		    <div class="modal-body">
	      	<form action=""  method="post">
	      		<input type="hidden" id="truckTypeId"/>
		         <div class="form-group">
                    <label class="col-sm-3 control-label">货车类型:</label>
                    <div class="col-sm-8">
                    	<label class="col-sm-3 control-label" id="truckTypeName"></label>
                    </div>
				 </div>
	      		 <div class="form-group">
	                <label class="col-sm-3 control-label">所属公司:</label>
	                <div class="col-sm-8">
		                <select class="form-control" id="companyId_company" >
							<#if companys??>
								<#list companys as company>
									<option value="${company.id}" <#if companyId?? && companyId==company.id>selected="selected"</#if>>${company.abbreviation?if_exists}</option>
								</#list>
							</#if>
						</select>
	                </div>
				 </div>
		         <div class="form-group">
	                <label class="col-sm-3 control-label">收费标准:</label>
	                <div class="col-sm-8">
		                <select class="form-control" id="areaId_company" >
							<!--<#if arealist??>
								<#list arealist as area>
								<option value="${area.id}" >${area.name?if_exists}</option>
								</#list>-->
							</#if>
						</select>
	                </div>
				 </div>
				 <div class="form-group">
             	 	<div class="col-sm-6">
            	 	</div>
            	 	<div class="col-sm-3">
				      <input  type="button" class="btn btn-primary" id="startService_company" value="开通">
				      <button type="button" class="btn btn-default"  data-dismiss="modal" id="close_modal_company">取消</button>
	        	  	</div>
	           </div>  
		  	</form>
	     	</div>
	     </div>
	  </div>
	</div>
</div>
<!--修改公司车型收费-->
<div class="form-horizontal">
	<div class="modal fade" id="dialog_truckTypeCompanyArea_update">
	   <div class="modal-dialog">
	     <div class="modal-content">
	    	<div class="modal-header">
		        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
	        	<h4 class="modal-title">修改公司收费</h4>
	        </div>
		    <div class="modal-body">
	      	<form action=""  method="post">
	      		<input type="hidden" id="companyId_update"/>
	      		<input type="hidden" id="truckTypeId_update"/>
	      		<input type="hidden" id="truckTypeCompanyId"/>
		         <div class="form-group">
                    <label class="col-sm-3 control-label">货车类型:</label>
                    <div class="col-sm-8">
                    	<label class="control-label" id="truckTypeName_update"></label>
                    </div>
				 </div>
	      		 <div class="form-group">
	                <label class="col-sm-3 control-label">所属公司:</label>
	                <div class="col-sm-8">
	                	<label id="companyName_update" class="control-label" ></label>
	                </div>
				 </div>
		         <div class="form-group">
	                <label class="col-sm-3 control-label">收费标准:</label>
	                <div class="col-sm-8">
		                <select class="form-control" id="areaId_company_update" >
							<!--<#if arealist??>
								<#list arealist as area>
								<option value="${area.id}" >${area.name?if_exists}</option>
								</#list>
							</#if>-->
						</select>
	                </div>
				 </div>
				 <div class="form-group">
             	 	<div class="col-sm-6">
            	 	</div>
            	 	<div class="col-sm-3">
				      <input  type="button" class="btn btn-primary" id="startService_company_update" value="修改">
				      <button type="button" class="btn btn-default" data-dismiss="modal" id="close_modal_company_update">取消</button>
	        	  	</div>
	           </div>  
		  	</form>
	     	</div>
	     </div>
	  </div>
	</div>
</div>


</@override>
<@override name="footer">
<script type="text/javascript">
  var isMainCompany=false;
  var deleteTrcukType = false;
  <@shiro.hasPermission name='deleteFreightType'>
	  deleteTrcukType = true;         
  </@shiro.hasPermission>
  <@shiro.isMainCompany>
      isMainCompany=true;
  </@shiro.isMainCompany>
</script>
<script src="${ctx}/assets/js/bootstrap-datetimepicker.min.js"></script>
<script src="${ctx}/assets/js/bootstrap-datetimepicker.zh-CN.js"></script>
<script src="${ctx}/assets/js/ajaxfileupload.js"></script>
<script src="${ctx}/assets/js/jquery.autocomplete.min.js"></script>
<script src="${ctx}/assets/js/jquery.paging.min.js"></script>
<script src="${ctx}/assets/js/freight/truckType2.js"></script>
<script src="${ctx}/assets/js/chosen.jquery.min.js"></script>
<script type="text/javascript">
	var thisButton;
	function deleteTruckType() {
	    $.get('${ctx}/freight/deleteTruckType',{'truckTypeId':thisButton.attr("data-value")},function(data){
	            if(data.success){
	            	thisButton.parent().parent().parent().parent().parent().remove();
	                $.scojs_message('类型删除成功', $.scojs_message.TYPE_OK);
	                 setTimeout(function(){
							window.location.reload(true);
						}, 500);
	            } else {
	                $.scojs_message(data.msg, $.scojs_message.TYPE_ERROR);
	                 setTimeout(function(){
							window.location.reload(true);
						}, 1000);
	            }
	    },'json');
	}
	
	// 选择车辆图片
	function checkCarImg() {
		$(".car_img_div .car_img_bor").click(function () {
			$this = $(this);
			$this.css({"borderColor":"#10c55b"})
			var src = $this.find("img").attr("src");
			$("#car_img").val(src);
			$this.css({"border":"2px dashed #10c55b"})
			$this.siblings().css({"border":"2px dashed #fff"})
		})
		$("#car_img_update .car_img_bor").click(function () {
			$this = $(this);
			$this.css({"borderColor":"#10c55b"})
			var src = $this.find("img").attr("src");
			$("#car_img2").val(src);
			$this.css({"border":"2px dashed #10c55b"})
			$this.siblings().css({"border":"2px dashed #fff"})
		})
	}
	$(document).ready(function(){
	
		checkCarImg() // 选择车辆图片
	    
	    $('body').on('click', '.deletethis', function() {
	    //$(".deletethis").click(function(){
	          thisButton = $(this);
	          var confirm = $.scojs_confirm({
	            content: "你真的要删除该车型吗？已经开通的公司该车型也会被取消开通!",
	            action:deleteTruckType
	          });
	          confirm.show();
	    });
	    
		
			
	//添加货车类型
	    $(".addCar").click(function(){
	    	$('#dialog_car').modal();
	    });
   		$("#save").click(function(){
	     		//var companyId=$('#companyId').val();
	     		//var companyName=$('#companyId').find("option:selected").text();
	     		var typeName=$('#typeName').val();
	     		var len=$('#len').val();
	     		var width=$('#width').val();
	     		var height=$('#height').val();
	     		var carryingCapacity=$('#carryingCapacity').val();
	     		var cangointotown=$('input[name="cangointotown"]:checked ').attr("value");
	     	//	var areaId = $("#areaId").val();
	     		var sequence = $("#sequence").val();
	     		var img = $("#car_img").val()
	     		console.log(img)
	     		<#--<@shiro.isMainCompany>
	     		if(companyId==""){
	     			$.scojs_message("请选择公司", $.scojs_message.TYPE_ERROR);
	     			return false;
	     		}
	     		</@shiro.isMainCompany>
	     		-->
	     		if(typeName.trim()==""){
	     			$.scojs_message("请输入货车类型", $.scojs_message.TYPE_ERROR);
	     			return false;
	     		} else if (typeName.length > 8) {
	     			$.scojs_message("类型名称字数最多8个", $.scojs_message.TYPE_ERROR);
	     			return false;
	     		}
	     		
	     		if(len.trim()==""){
	     			$.scojs_message("请输入货车长度", $.scojs_message.TYPE_ERROR);
	     			return false;
	     		} else {
	     			if (len.indexOf(".") == 0) {
	     				$.scojs_message("请输入正确长度", $.scojs_message.TYPE_ERROR);
	     				return false;
	     			} else if (len.indexOf(".") > 0) {
	     				if (len.split(".")[1].length > 2 ) {
	     					$.scojs_message("长度最大精度为2位，例：1.11", $.scojs_message.TYPE_ERROR);
	     					return false;
	     				}
	     			}
	     		}
	     		
	     		if(width.trim()==""){
	     			$.scojs_message("请输入货车宽度", $.scojs_message.TYPE_ERROR);
	     			return false;
	     		} else {
	     			if (width.indexOf(".") == 0) {
	     				$.scojs_message("请输入正确宽度", $.scojs_message.TYPE_ERROR);
	     				return false;
	     			} else if (width.indexOf(".") > 0) {
	     				if (width.split(".")[1].length > 2 ) {
	     					$.scojs_message("宽度最大精度为2位，例：1.11", $.scojs_message.TYPE_ERROR);
	     					return false;
	     				}
	     			}
	     		}
	     		if(height.trim()==""){
	     			$.scojs_message("请输入货车高度", $.scojs_message.TYPE_ERROR);
	     			return false;
	     		} else {
	     			if (height.indexOf(".") == 0) {
	     				$.scojs_message("请输入正确高度", $.scojs_message.TYPE_ERROR);
	     				return false;
	     			} else if (height.indexOf(".") > 0) {
	     				if (height.split(".")[1].length > 2 ) {
	     					$.scojs_message("高度最大精度为2位，例：1.11", $.scojs_message.TYPE_ERROR);
	     					return false;
	     				}
	     			}
	     		}
	     		
	     		if(carryingCapacity.trim()==""){
	     			$.scojs_message("请输入货车载重量", $.scojs_message.TYPE_ERROR);
	     			return false;
	     		} else {
	     			if (carryingCapacity.indexOf(".") == 0) {
	     				$.scojs_message("请输入正确重量", $.scojs_message.TYPE_ERROR);
	     				return false;
	     			} else if (carryingCapacity.indexOf(".") > 0) {
	     				if (carryingCapacity.split(".")[1].length > 2 ) {
	     					$.scojs_message("重量最大精度为2位，例：1.11", $.scojs_message.TYPE_ERROR);
	     					return false;
	     				}
	     			}
	     		}
	     		
	     		if(img.trim() == "") {
	     			$.scojs_message("请选择车辆图片", $.scojs_message.TYPE_ERROR);
	     			return false;
	     		}
				$.post('${ctx}/freight/newCreateTruckType',
				{'typeName':typeName,'len':len,'width':width,'height':height,'carryingCapacity':carryingCapacity,'cangointotown':cangointotown,'sequence':sequence,'img':img},
				function(data){
				console.log(data)
		           if(data.success){ 
		                $.scojs_message(data.message, $.scojs_message.TYPE_OK);
		                setTimeout(function(){
							window.location.reload(true);
						}, 300);
			       }else{
		                $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
		                setTimeout(function(){
							window.location.reload(true);
						}, 800);
			       }
			    },'json');
			    $('#dialog_car').modal("hide");
	     });
	    $("#close_modal").click(function(){
			$('#dialog_car').modal("hide");
		});
		
		
//修改货车类型
		$('body').on('click', '.updateCarType', function() {
	    //$(".updateCarType").click(function(){
	    $('#dialog_car_update').modal();
	    	var truckTypeId=$(this).attr("truckTypeId");
			$.ajax({
             type: "GET",
             url: "${ctx}/freight/findByTruckTypeId",
             data: {'truckTypeId':truckTypeId},	
             dataType: "json",
             success: function(object){ 
             			var truck=object.truckType;
             			$("#truckTypeId").val(truckTypeId);
             			$("#typeName2").val(truck.typeName);
             			$("#len2").val(truck.len);
             			$("#width2").val(truck.width);
             			$("#height2").val(truck.height);
             			$("#carryingCapacity2").val(truck.carryingCapacity);
             			$("#sequence2").val(truck.sequence);
             			
             			// 加载更新时的图片
             			var img = truck.img;
             			$("#car_img_update .car_img_bor").find("img").parent().css({"border":"2px dashed #fff"})
             			$("#car_img_update .car_img_bor").find("img[src='"+ img +"']").parent().css({"borderColor":"#10c55b"})
             			
             			if(truck.cangointotown){
             			    document.getElementById('you').checked=true;
             			}else{
             			   document.getElementById('wu').checked=true;
             			}
			    	 }
	         });
         
	    	
	    });
	    
	    $("#update").click(function(){
	    		var truckTypeId=$("#truckTypeId").val()
	     		var typeName=$('#typeName2').val();
	     		var len=$('#len2').val();
	     		var width=$('#width2').val();
	     		var height=$('#height2').val();
	     		var carryingCapacity=$('#carryingCapacity2').val();
	     		var cangointotown=$('input[name="cangointotown2"]:checked ').attr("value");
	     		var sequence=$('#sequence2').val();
	     		var img=$('#car_img2').val();
	     		
	     		if(typeName.trim()==""){
	     			$.scojs_message("请输入货车类型", $.scojs_message.TYPE_ERROR);
	     			return false;
	     		} else if (typeName.length > 8) {
	     			$.scojs_message("类型名称字数最多8个", $.scojs_message.TYPE_ERROR);
	     			return false;
	     		}
	     		
	     		if(len.trim()==""){
	     			$.scojs_message("请输入货车长度", $.scojs_message.TYPE_ERROR);
	     			return false;
	     		} else {
	     			if (len.indexOf(".") == 0) {
	     				$.scojs_message("请输入正确长度", $.scojs_message.TYPE_ERROR);
	     				return false;
	     			} else if (len.indexOf(".") > 0) {
	     				if (len.split(".")[1].length > 2 ) {
	     					$.scojs_message("长度最大精度为2位，例：1.11", $.scojs_message.TYPE_ERROR);
	     					return false;
	     				}
	     			}
	     		}
	     		
	     		if(width.trim()==""){
	     			$.scojs_message("请输入货车宽度", $.scojs_message.TYPE_ERROR);
	     			return false;
	     		} else {
	     			if (width.indexOf(".") == 0) {
	     				$.scojs_message("请输入正确宽度", $.scojs_message.TYPE_ERROR);
	     				return false;
	     			} else if (width.indexOf(".") > 0) {
	     				if (width.split(".")[1].length > 2 ) {
	     					$.scojs_message("宽度最大精度为2位，例：1.11", $.scojs_message.TYPE_ERROR);
	     					return false;
	     				}
	     			}
	     		}
	     		if(height.trim()==""){
	     			$.scojs_message("请输入货车高度", $.scojs_message.TYPE_ERROR);
	     			return false;
	     		} else {
	     			if (height.indexOf(".") == 0) {
	     				$.scojs_message("请输入正确高度", $.scojs_message.TYPE_ERROR);
	     				return false;
	     			} else if (height.indexOf(".") > 0) {
	     				if (height.split(".")[1].length > 2 ) {
	     					$.scojs_message("高度最大精度为2位，例：1.11", $.scojs_message.TYPE_ERROR);
	     					return false;
	     				}
	     			}
	     		}
	     		
	     		if(carryingCapacity.trim()==""){
	     			$.scojs_message("请输入货车载重量", $.scojs_message.TYPE_ERROR);
	     			return false;
	     		} else {
	     			if (carryingCapacity.indexOf(".") == 0) {
	     				$.scojs_message("请输入正确重量", $.scojs_message.TYPE_ERROR);
	     				return false;
	     			} else if (carryingCapacity.indexOf(".") > 0) {
	     				if (carryingCapacity.split(".")[1].length > 2 ) {
	     					$.scojs_message("重量最大精度为2位，例：1.11", $.scojs_message.TYPE_ERROR);
	     					return false;
	     				}
	     			}
	     		}
	     		
				$.get('${ctx}/freight/newUpdateTruckType',
				{'truckTypeId':truckTypeId,'typeName':typeName,'len':len,'width':width,
				'height':height,'carryingCapacity':carryingCapacity,'cangointotown':cangointotown,'sequence':sequence,'img':img},
				function(data){
		           if(data.success){ 
		          		$('#dialog_car_update').modal("hide");
		                $.scojs_message(data.msg, $.scojs_message.TYPE_OK);
		                setTimeout(function(){
							window.location.reload(true);
						}, 500);
			       }else{
			      		$('#dialog_car_update').modal("hide");
		                $.scojs_message(data.msg, $.scojs_message.TYPE_ERROR);
		                setTimeout(function(){
							window.location.reload(true);
						}, 800);
			       }
			    });
	     });
	     
	    $("#close_modal_update").click(function(){
			$('#dialog_car_update').modal("hide");
			 document.getElementById('you').checked=false;
			 document.getElementById('wu').checked=false;
		});
		
		$(document).on("click",".subscribeTruckType",function(){
		$("#truckTypeName").text("");
		$("#truckTypeId").val("");
		$("#truckTypeId").val($(this).attr("trucktypeId"));
		$("#truckTypeName").text($(this).attr("typeName"));
		$("#dialog_truckTypeCompany_create").modal();
		
		});
		$("#startService_company").click(function(){
		if($('#companyId_company').val().trim()==null  || $('#companyId_company').val().trim()==""){
			$.scojs_message("请选择开通公司！", $.scojs_message.TYPE_ERROR);
			return false;
		}
		if($('#areaId_company').val().trim()==null  || $('#areaId_company').val().trim()==""){
			$.scojs_message("请选择收费标准！", $.scojs_message.TYPE_ERROR);
			return false;
		}
		$.post('${ctx}/freight/subscribeTruckType',{
		companyId:$('#companyId_company').val(),
		truckTypeId:$('#truckTypeId').val(),
		areaId:$('#areaId_company').val(),
		companyName:$('#companyId_company').find("option:selected").text()
		},function(data){
		   if(data.success){
	                $.scojs_message(data.message, $.scojs_message.TYPE_OK);
	                setTimeout(function(){
						window.location.reload(true);
					}, 800);
		       }else{
	                $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
		       }
		},"json");
		
		});
		
		
		$(document).on("click",".updateTruckType_company",function(){
		$("#truckTypeName_update").html($(this).attr('trucktypename'));
		$("#truckTypeCompanyId").val($(this).attr("data-value"))
		$("#truckTypeId_update").val($(this).attr('trucktypeid'));
		$("#companyId_update").val($(this).attr('companyid'));
		var companyName=$(this).attr('companyname');
		$("#companyName_update").html(companyName);
		var areaId=$(this).attr('areaid');
		var areaName=$(this).attr('areaName');
		//生成收费标准的option，并选中值
    	 $.ajax({
	        url :'${ctx}/freight/truckTypeData',
	        type:'GET',
	        async:false,
	        dataType : 'json',
	        data : {},
	        success : function(result){
	        	//生成各个收费标准的option，并选中值
	        	var areaUpdateSelect =  getAreaContentSelected(result,areaId);
	        	$("#areaId_company_update").html(areaUpdateSelect).chosen().change(function(){});
	        	$("#areaId_company_update option").each(function(index,element){
	        		var flag = false;
	                if($(element).attr("selected") == "selected"){
	                	$("#areaId_company_update").next().find("a").text(areaName);
	                	return false;
	               }
	               if(!flag){
	               		$("#areaId_company_update").next().find("a").html("<em>请选择收费标准</em>");
	               }
	            });
	        }
	  	 });
	  	 //收费标准下拉框选值变化，改变下拉框显示值
	 	 $(document).on("click",".active-result",function(){
	 		 $($(this).parent().parent().parent().children()[0]).html($(this).text())
	 	 });
//		$("#areaId_company_update option").each(function(index,element){
//		  	if($(element).attr("value")==areaId){
//		 		$(element).attr("selected","selected");
//		 		return false;
//		 	}
//		});
    	$('#dialog_truckTypeCompanyArea_update').modal();
	});
	
	 $(document).on("click","#startService_company_update",function(){
	 	var areaText = $("#areaId_company_update").next().find("a").text();
    	if($('#areaId_company_update').val().trim()==null  || areaText =="请选择收费标准"){
			$.scojs_message("请选择车收费标准！", $.scojs_message.TYPE_ERROR);
			return false;
		}
		
		$.post('${ctx}/freight/updateTruckTypeCompany',
			{id:$("#truckTypeCompanyId").val(),
			areaId:$('#areaId_company_update').val()},
			function(data){
	           if(data.success){
	                $.scojs_message(data.message, $.scojs_message.TYPE_OK);
	                setTimeout(function(){
						window.location.reload(true);
					}, 800);
		       }else{
	                $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
		       }
		    },'json');
		
    });	
		
		var thisButton_company = null;
		 $(document).on("click",".deleteTypeCompany",function(){
	          thisButton_company = $(this);
	          var confirm = $.scojs_confirm({
	            content: "你真的要取消开通该车型吗？货车车型不会被删除!",
	            action: deleteTruckTypeCompany
	          });
	          confirm.show();
	    });
		function deleteTruckTypeCompany(){
		if(thisButton_company.attr("data-value").trim()==null  || thisButton_company.attr("data-value").trim()==""){
			$.scojs_message("公司车型不存在！", $.scojs_message.TYPE_ERROR);
			return false;
		}
	    $.post('${ctx}/freight/deleteTruckTypeCompany',{'truckTypeCompanyId':thisButton_company.attr("data-value")},function(data){
            if(data.success){
            	thisButton_company.parent().parent().parent().remove();
                $.scojs_message('车型取消成功', $.scojs_message.TYPE_OK);
                 setTimeout(function(){
						window.location.reload(true);
					}, 800);
            } else {
                $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
            }
	    },'json');
		
		
		}
		
	});
	$('input[type="number"]').bind('input propertychange', function() {
	    if(window.parseFloat($(this).val())>window.parseFloat($(this).attr("max"))){
	      $.scojs_message('输入数值过大', $.scojs_message.TYPE_ERROR);
	      $(this).val("");
	    }else if(window.parseFloat($(this).val())<0){
	        $.scojs_message('输入数值过小', $.scojs_message.TYPE_ERROR);
	        $(this).val("");
	    }
	});
function getAreaContentSelected(result,id){
	
	var areaContent = '';
	var areaList = result.areaList;
	$(areaList).each(function(index,data){
		if(id == data.id ){
			areaContent+="<option value='"+data.id+"' selected='selected'>"+data.name+"</option>"
		}else{
			areaContent+="<option value='"+data.id+"'>"+data.name+"</option>"
		}
		
	});
	return areaContent;
};
</script>
</@override>
<@extends name="../layout.ftl"/>